package com.struts.action;

import com.opensymphony.xwork2.ActionSupport;
import com.struts.pojo.User;
import com.struts.service.UserService;
import com.struts.service.impl.UserServiceImpl;

public class LoginAction extends ActionSupport{
	
	private UserService userService = new UserServiceImpl() ;
	
	private User user ;
	
	public User getUser() {
		return user;
	}

	public void setUser(User user) {
//		System.out.println("LoginAction setUser()");
		this.user = user;
	}

	public UserService getUserService() {
		return userService;
	}

	public void setUserService(UserService userService) {
		this.userService = userService;
	}

	public String login() {
		User user2 = userService.login(user.getUsername(), user.getPassword()) ;
		if(user2 == null) { //用户名或密码错误
			this.addActionError("用户名或密码错误") ;
			return "input" ;
		} 
		return "home";
	}

}
